package com.demo.bean;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
/**
 * 用户类
 * Component(value = "userInfo") //相当于在配置文件中　<bean id="computer" class="……"></bean>
 * Scope(value = "prototype") //配置创建对象是否是以单列模式进行创建
 * <p>
 * Autowired：自动装配，默认按type注入
 * Resource(name = "book")：默认按name注入，可以通过name和type属性进行选择性注入
 * Qualifier：按照名称装配
 * @author hlf
 * @version 1.0
 * @date 2022/8/3 14:59
 */
@Scope(value = "prototype")
@Component(value = "userInfo")
public class UserInfo {

    private String name;

    private int age;

    @Autowired(required = false)
    private CarInfo carInfo;

    @Resource(name = "mobile")
    private Mobile mobile;

    @Qualifier("computerInfo")
    @Autowired(required = false)
    private ComputerInfo computerInfo;

    public UserInfo() {
    }

    public UserInfo(String name, int age, CarInfo carInfo, Mobile mobile, ComputerInfo computerInfo) {
        this.name = name;
        this.age = age;
        this.carInfo = carInfo;
        this.mobile = mobile;
        this.computerInfo = computerInfo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public CarInfo getCarInfo() {
        return carInfo;
    }

    public void setCarInfo(CarInfo carInfo) {
        this.carInfo = carInfo;
    }

    public Mobile getMobile() {
        return mobile;
    }

    public void setMobile(Mobile mobile) {
        this.mobile = mobile;
    }

    public ComputerInfo getComputerInfo() {
        return computerInfo;
    }

    public void setComputerInfo(ComputerInfo computerInfo) {
        this.computerInfo = computerInfo;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", car=" + carInfo +
                ", mobile=" + mobile +
                ", computer=" + computerInfo +
                '}';
    }
}
